package com.leetcode.LC;

import java.util.Arrays;

public class LC88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {

        int k=m+n;
        while (n>0&&m>0){
            if(nums2[n-1]>nums1[m-1]){
                k--;
                nums1[k]=nums2[n-1];
                n--;
            }else {
                k--;
                nums1[k]=nums1[m-1];
                m--;
            }
        }
        if (n!=0){
            for (int i = 0; i < n; i++) {
                nums1[i]=nums2[i];
            }
        }
        for (int i : nums1) {
            System.out.print(i+",");
        }
    }

    public void merge2(int[] nums1, int m, int[] nums2, int n) {
        if (n!=0){
            for (int i = 0; i < n; i++) {
                nums1[m+i]=nums2[i];
            }
        }
        Arrays.sort(nums1);

        for (int i : nums1) {
            System.out.print(i+",");
        }
    }

    public static void main(String[] args) {
        new LC88().merge2(new int[]{2,3,4,5,0,0,0},4,new int[]{1,5,6},3);
    }
}
